<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书-赠书列表</title>
    <link rel="icon" href="/static/images/t_logo.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/lyk-global.css" />
    <link rel="stylesheet" href="/static/elementui/lib/theme-chalk/index.css">
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script src="/static/js/requestApi.js" type="text/javascript"></script>
    <script src="/static/js/vue/vue.js"></script>
    <!-- 引入elementui -->
    <script src="/static/elementui/js/element.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/axios-config.js"></script>
    <script src="/static/js/utilJs.js"></script>
</head>
<style>
    *{
        font-size: 14px
    }
    [v-cloak] {
        display: none;
    }
</style>
<body style="background-color: #fff">
<div id="app" v-cloak>
    <div class="mt-8 ml-4">
        <div class="df-aic ">
            <el-input placeholder="请输入赠书人" size="small" style="width:200px;" class="ml-2" v-model="queryParam.donationName" @keyup.native.enter="getTableDataMethod(true)"></el-input>
            <el-input placeholder="请输入赠书信息" size="small" style="width:200px;" class="ml-2" v-model="queryParam.donationInfo" @keyup.native.enter="getTableDataMethod(true)" class="ml-2"></el-input>
            <el-date-picker
                    v-model="queryParam.donationTime"
                    type="month"
                    placeholder="请选择赠书时间" style="width:200px;" class="ml-2" size="small" value-format="yyyy-MM">
            </el-date-picker>
            <el-button type="primary" size="small" class="ml-2" @click="getTableDataMethod(true)">搜索</el-button>
            <el-button type="primary" size="small" class="ml-2" @click="addOrEditDonationMethod('新增')">新增赠书芳名录</el-button>
            <span class="ml-2 copy-a" @click="donationBookGuide">赠书指引</span>
        </div>
        <el-table :data="tableData" v-loading="tableDataLoading" class="mt-4">
            <el-table-column prop="donationName" label="赠书人" width="150"></el-table-column>
            <el-table-column prop="donationInfo" label="赠书信息"></el-table-column>
            <el-table-column prop="donationTimeDesc" label="赠书时间"></el-table-column>
            <el-table-column prop="createTime" label="添加时间"></el-table-column>

            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button size="small" @click="addOrEditDonationMethod('修改',scope.row)" class="mb-2">编辑赠书芳名录</el-button>
                    <el-popconfirm :title='"是否删除该条数据？"'
                                   @confirm="deleteDonationMethod(scope.row)">
                        <el-button slot="reference" type="danger" size="small" v-loading="deleteLoading"  class="mt-2">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <el-pagination background layout="total,sizes,prev, pager, next" :total="tableDataPaging.total"
                   :page-sizes="[10, 20, 50]"
                   prev-text="上一页" next-text="下一页"
                   :page-size="tableDataPaging.pageSize"
                   :current-page="tableDataPaging.currentPage"
                   @current-change="tableDataPagingChange"
                   @prev-click="tableDataPagingChange" @next-click="tableDataPagingChange"
                   @size-change="tableDataPagingSizeChange"
                   style="float:right;margin-top: 40px;padding-bottom:50px;">
    </el-pagination>

    <el-dialog :title="addOrEditDonationDialogTitle" :visible.sync="addOrEditDonationDialogVisible" width="1200px" :close-on-click-modal="false" append-to-body>
        <div class="df-aic-jcc mt-9 mb-9">
            <el-form ref="donationForm" :model="donationForm" label-width="150px" >
                <el-form-item label="赠书人：" prop="donationName" required>
                    <el-input v-model="donationForm.donationName" style="width:400px;"  size="small" placeholder="请输入赠书人"></el-input>
                </el-form-item>
                <el-form-item label="赠书信息：" prop="donationInfo" required>
                    <el-input v-model="donationForm.donationInfo" style="width:400px;" placeholder="请输入赠书信息" size="small"></el-input>
                </el-form-item>
                <el-form-item label="赠书时间：" prop="donationTime" required>
                    <el-date-picker
                            v-model="donationForm.donationTime"
                            type="month"
                            placeholder="请选择赠书时间" style="width:200px;" size="small" value-format="yyyy-MM">
                    </el-date-picker>
                </el-form-item>
            </el-form>
        </div>

        <div class="df-aic-jcc mt-9 mb-9">
            <el-button @click="addOrEditDonationDialogSureMethod" type="primary" size="small">确定</el-button>
            <el-button size="small" class="ml-6" @click="addOrEditDonationDialogVisible = false">取消</el-button>
        </div>

    </el-dialog>

    <el-dialog title="赠书指引" :visible.sync="donationBookGuideDialogVisible" width="1200px" :close-on-click-modal="false" append-to-body>
        <div class="df-aic-jcc mt-9 mb-9">
            <h1 style="text-indent: 30px;font-size:18px;">
                欢迎团体以及个人捐赠文献，特别是反映当地人文、社会、文化、政治、经济、地理、历史等内容且有一定史料价值的文献资料。
                文献一经接受，其产权即归本馆所有，同时向捐赠者颁发捐赠证书。我馆将根据入藏的相关标准对捐赠文献进行验收加工，纳入馆藏体系。
                凡不符合入藏标准的文献资料不纳入馆藏体系另行处理。
            </h1>

        </div>

        <div class="df-aic-jcc mt-9 mb-9">
            <el-button size="small" class="ml-6" @click="donationBookGuideDialogVisible = false">取消</el-button>
        </div>

    </el-dialog>

</div>
</body>

<script type="text/javascript">
    const vm = new Vue({ // 配置对象 options
        // 配置选项(option)
        el: '#app', // element: 指定用vue来管理页面中的哪个标签区域
        components: {
        },
        data() {
            return {
                addOrEditDonationDialogTitle:'',
                addOrEditDonationDialogVisible:false,
                donationForm:{
                    id:"",
                    donationName:"",
                    donationInfo:"",
                    donationTime:""
                },
                deleteLoading : false,
                queryParam : {
                    donationName:"",
                    donationInfo:"",
                    donationTime:"",
                },
                tableData : [],
                tableDataLoading : false,
                tableDataPaging : {
                    currentPage : 1,
                    pageSize : 10,
                    total : 0,
                },
                donationBookGuideDialogVisible:false,


            }
        },
        mounted() {
            let that = this;
            this.$nextTick(function () {
                this.getTableDataMethod();
            });
        },
        methods: {
            addOrEditDonationMethod(title,row){
                let that = this;
                that.addOrEditDonationDialogVisible = true;
                this.$nextTick(function () {
                    this.$refs['donationForm'].resetFields();//还原数据
                    that.addOrEditDonationDialogTitle = title;
                    if(row){
                        let deepCopyRow = JSON.parse(JSON.stringify(row));
                        that.donationForm = deepCopyRow;//深拷贝一下
                    }
                });
            },
            addOrEditDonationDialogSureMethod(){
                let that = this;
                let deepCopyForm = JSON.parse(JSON.stringify(that.donationForm));
                deepCopyForm.donationName = $.trim(deepCopyForm.donationName);
                deepCopyForm.donationInfo = $.trim(deepCopyForm.donationInfo);
                deepCopyForm.donationTime = $.trim(deepCopyForm.donationTime);
                if(!deepCopyForm.donationName){
                    that.$message.error("请输入赠书人");
                    return;
                }
                if(!deepCopyForm.donationInfo){
                    that.$message.error("请输入赠书信息");
                    return;
                }
                if(!deepCopyForm.donationTime){
                    that.$message.error("请输入赠书时间");
                    return;
                }
                deepCopyForm.donationTime = deepCopyForm.donationTime +"-01";
                let url = "";
                if (!deepCopyForm.id) {
                    url = "donation/addDonation";
                } else {
                    url = "donation/updateDonation";
                }
                requestApiTB(url, deepCopyForm, 'POST', function (res) {
                    if (res.code === 0) {
                        that.$message.success("执行成功");
                        that.addOrEditDonationDialogVisible = false;
                        that.getTableDataMethod(true);
                    } else {
                        that.$message.error(res.msg);
                    }
                });

            },

            tableDataPagingChange(val) {
                let that = this;
                that.tableDataPaging.currentPage = val;
                that.getTableDataMethod();
            },
            tableDataPagingSizeChange(val) {
                let that = this;
                that.tableDataPaging.pageSize = val;
                that.getTableDataMethod();
            },

            //获取表格的数据
            getTableDataMethod(isChongZhi){
                let that = this;
                if (isChongZhi) {
                    this.tableDataPaging.currentPage = 1;
                }
                const {donationName,donationInfo,donationTime} = this.queryParam
                let queryData = {
                    donationName: $.trim(donationName),
                    donationInfo: $.trim(donationInfo),
                    donationTime: $.trim(donationTime),
                    pageNum: this.tableDataPaging.currentPage,
                    pageSize: this.tableDataPaging.pageSize,
                }
                this.tableDataLoading = true;
                that.tableData = [];
                axios.post('/donation/getDonationList', queryData)
                    .then(result => {
                        let res = result.data;
                        this.tableDataLoading = false;
                        if (res.code === 0) {
                            that.tableData = res.data.list;
                            that.tableDataPaging.total = res.data.total;
                        }
                    }).catch(error => {
                    that.$message.error("error");
                    this.tableDataLoading = false
                })
            },
            deleteDonationMethod(row){
                let that = this;
                if(!row.id){
                    that.$message.error("尚无id");
                    return;
                };
                that.deleteLoading = true;
                requestApiTB("donation/delDonation",{"id" : row.id}, "POST", function(res){
                    that.deleteLoading = false;
                    if(res.code === 0){
                        that.$message.success("删除成功");
                        that.getTableDataMethod(true);
                    }else{
                        that.$message.error(res.msg);
                    }
                });
            },

            //赠书指引
            donationBookGuide(){
                let that = this;
                that.donationBookGuideDialogVisible = true;
            },




        }
    })
</script>
</html>